class GamePkProgressBar extends eui.Component implements eui.UIComponent {
	public constructor() {
		super();
	}

	private Blue: eui.Image;
	private Red: eui.Image;
	private ShowGroup: eui.Group;

	private currentPercent: number;
	private targetPercent: number;
	private changeSpeed: number = 0.01;
	private loopEvent: boolean = false;

	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}


	protected childrenCreated(): void {
		super.childrenCreated();

		console.log("GamePkProgressBar.childrenCreated");

		if (this.ShowGroup) {
			console.log("GamePkProgressBar.childrenCreated has ShowGroup" + this.width);
			console.log(this.Blue.width)
			console.log(this.Red.width);
		}

		this.currentPercent = 0.5;
		this.Blue.width = this.width * (1 - this.currentPercent);
		this.Red.width = this.width * (this.currentPercent);
	}

	private loop(e: egret.Event) {
		//console.log("GamePkProgressBar.loop")

		if (this.currentPercent < this.targetPercent) {
			this.currentPercent += this.changeSpeed;
			if (this.currentPercent > this.targetPercent) {
				this.currentPercent = this.targetPercent;
			}
		} else if (this.currentPercent > this.targetPercent) {
			this.currentPercent -= this.changeSpeed;
			if (this.currentPercent < this.targetPercent) {
				this.currentPercent = this.targetPercent;
			}
		}
		if (this.currentPercent == this.targetPercent) {
			this.removeEventListener(egret.Event.ENTER_FRAME, this.loop, this);
			this.loopEvent = false;
		}

		this.Blue.width = this.width * (1 - this.currentPercent);
		this.Red.width = this.width * (this.currentPercent);
	}

	public SetProgress(red: number, blue: number): void {
		var total: number = red + blue
		this.targetPercent = red / total;

		if (this.loopEvent == false) {
			this.loopEvent = true
			this.addEventListener(egret.Event.ENTER_FRAME, this.loop, this)
		}
	}
	public SetSpeed(speed: number): void {
		this.changeSpeed = speed;
	}
}